package com.example.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.example.music.MainActivity;
import com.example.music.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MusicListAdapter extends BaseAdapter {

	List<Map<String, Object>> fileList = new ArrayList<Map<String, Object>>();
	LayoutInflater inflater;

	public MusicListAdapter(Context context, List<Map<String, Object>> _list) {
		this.fileList = _list;
		inflater = LayoutInflater.from(context);
	}

	public void resetData(List<Map<String, Object>> _list) {
		this.fileList = _list;
	}

	@Override
	public int getCount() {
		return fileList.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater
					.inflate(R.layout.main_list_adaper_item, null);
			holder.fileName = (TextView) convertView
					.findViewById(R.id.txv_list_item_file_name);
			holder.filePic = (ImageView) convertView
					.findViewById(R.id.img_list_item_file_type);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.fileName.setText((CharSequence) fileList.get(position).get(
				"filename"));
		if (position == MainActivity.musicNum &&MusicControl.mMediaPlayer != null) {
				if (MusicControl.mMediaPlayer.isPlaying()) {
					holder.fileName.setTextColor(0xff0ae6a3);
				} else {
					holder.fileName.setTextColor(0xff9a9a1d);
				}
		} else {
			holder.fileName.setTextColor(0xff000000);
		}
		return convertView;
	}

	class ViewHolder {
		TextView fileName;
		ImageView filePic;
	}

}
